#include <QLabel>
#include <vector>

#include "../../uam/UserAccountManager.h"
#include "widgets/SPopupWindow.h"
class QSpacerItem;
class QDragEnterEvent;
class QDropEvent;
class QGridLayout;
class QLabel;
enum BrokerStatus { kEmpty, kBroker, kNumber };

class SLabel : public QLabel {
  Q_OBJECT
 public:
  SLabel(QWidget* parent = nullptr, BrokerStatus type = kEmpty,
         int brokerId = -1);
  ~SLabel();
  void setIndex(int index) { m_index = index; }
  int getIndex() { return m_index; }
  void setBrokerId(int id) { m_brokerId = id; }
  int getBrokerId() { return m_brokerId; }
  void changeLabelType(BrokerStatus kEmpty, int brokerId = -1);
  void applyStyleSheet();
  void paintNumber(int num) { m_paintNum = num; }
  void setHovered(bool hovered);
  BrokerStatus getSLabelStatus() { return m_type; }

 protected:
  void paintEvent(QPaintEvent* event) override;

 private:
  int m_paintNum = -1;
  QString m_styleSheet;
  QString m_txt;
  QColor m_st = nullptr;
  QColor m_end = nullptr;
  BrokerStatus m_type;
  int m_brokerId = -1;
  int m_index = -1;
};

class SetBrokerSortDlg : public SPopupWindow {
  Q_OBJECT
 public:
  SetBrokerSortDlg(QWidget* p = nullptr);
  void initBrokerSortDlg();
  void saveGlobalSettingConfig();

 protected:
  void paintEvent(QPaintEvent* event);
  void mousePressEvent(QMouseEvent* event) override;
  void dragEnterEvent(QDragEnterEvent* event) override;
  void dropEvent(QDropEvent* event) override;
  void dragMoveEvent(QDragMoveEvent* event) override;

 protected slots:
  void onAddButtonAuto();
  void onSaveAndExit();

 private:
  QPushButton* m_pBtnAddAuto = nullptr;
  QPushButton* m_pBtnSave = nullptr;
  CBrokerList m_brokerList;
  int m_sztime = 0;
  std::map<int, QRect> m_beSortRectMap;
  std::map<int, QRect> m_sortShowRectMap;
  bool m_bSavePos = false;
  std::vector<int> m_stlSortShow;  // 已选
  std::vector<int> m_stlBeSort;    // 待选
  std::vector<int> m_stlSaveId;
  SLabel* m_hoveredLabel = nullptr;
  int m_nEnableBroker = 0;
  int m_nDragIndex = -1;
  QGridLayout* m_gridLayout = nullptr;
};